# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Maintainer: Stuart Cardall <developer@it-offshore.co.uk>
pkgname=bitcoin
pkgver=26.1
pkgrel=1
pkgdesc="Decentralized P2P electronic cash system"
url="https://www.bitcoincore.org/"
# x86: segfault in check
arch="all !x86"
license="MIT"
makedepends="autoconf automake libtool boost-dev miniupnpc-dev
	qt5-qtbase-dev qt5-qttools-dev protobuf-dev libqrencode-dev libevent-dev chrpath zeromq-dev db-dev"
install="$pkgname.post-install $pkgname.post-upgrade $pkgname.pre-install"
subpackages="$pkgname-dev $pkgname-qt $pkgname-cli $pkgname-tx $pkgname-tests $pkgname-bench
	$pkgname-doc $pkgname-openrc"
source="https://bitcoincore.org/bin/bitcoin-core-$pkgver/bitcoin-$pkgver.tar.gz
	ssize_t.patch
	use-c-locale.patch
	$pkgname.initd
	$pkgname.conf
	"

prepare() {
	default_prepare
	./autogen.sh
}

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--mandir=/usr/share/man \
		--with-incompatible-bdb \
		--with-gui=qt5 \
		--with-utils \
		--disable-ccache \
		--disable-static \
		--enable-hardening \
		--enable-wallet
	make
}

check() {
	make check
}

package() {
	make install DESTDIR="$pkgdir"
	install -m755 -D "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -m600 -D "$srcdir"/$pkgname.conf "$pkgdir"/etc/$pkgname.conf
	rm -f "$pkgdir"/usr/lib/*.la
}

qt() {
	pkgdesc="Bitcoin with a Qt frontend & QR Code support"
	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/$pkgname-qt "$subpkgdir"/usr/bin/
}

cli() {
	pkgdesc="Bitcoin CLI"
	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/$pkgname-cli "$subpkgdir"/usr/bin/
}

tx() {
	pkgdesc="Bitcoin TX (Transaction Tool)"
	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/$pkgname-tx "$subpkgdir"/usr/bin/
}

tests() {
	pkgdesc="Bitcoin & Bitcoin-QT Unit Tests)"
	mkdir -p "$subpkgdir"/usr/bin
	chrpath -d "$pkgdir"/usr/bin/test_$pkgname
	mv "$pkgdir"/usr/bin/test_$pkgname-qt "$subpkgdir"/usr/bin/
	mv "$pkgdir"/usr/bin/test_$pkgname "$subpkgdir"/usr/bin/
}

bench() {
	pkgdesc="Bitcoin Benchmarking Tools)"
	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/bench_$pkgname "$subpkgdir"/usr/bin/
}

dev() {
	mkdir -p "$subpkgdir"/usr
	mv "$pkgdir"/usr/lib "$subpkgdir"/usr/
	mv "$pkgdir"/usr/include "$subpkgdir"/usr/
}

sha512sums="
5aa99d97493d220acf10c806fa3386f26e1cf7357ec590bed9f5b42881e764656eecb938c0f7cfbc1d9c254f04138f3919b3dc803b7863e0dfd846a7cd809e8c  bitcoin-26.1.tar.gz
b150ed46dc8ae230acd1ac1930936670f4195bf1bdd3fefaf743919b99a2de3a8ec5d0012df3b1b1280f3f31abf961ab02de461742799bffbeda7bfe5e0adb14  ssize_t.patch
7868c3cd34ce7c7340d68e8d2bc357f24a8ba82e968a37be949d4edf4f63edf32feff644ad26bf178eaa1eee28b9d43bd2abaf71ff6a9bdea91b57b5e4c80578  use-c-locale.patch
c88ca4f0c8a3179dbac274db1719983352caa5074b236e59d8fe31ab45ffa99bd90c1a566c4459261a9dcdcc990b826f3466c77aa7a32cf9fb15529a510ac7fd  bitcoin.initd
a65a81b8c58639f6aaa41b94425f1d5e31ebc25f682a51e0a80865caf96eaa0642ccba485bb9182743d3aabb624e5b4d0dd804172263d82e93bf32554913e2f3  bitcoin.conf
"
